package WebSocket.controller;

import WebSocket.component.SingleWebSocketServer;
import WebSocket.component.WebSocketServer;
import WebSocket.constant.MessageBody;
import com.alibaba.fastjson.JSON;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Set;

@RestController
public class SocketController {


    @Autowired
    private WebSocketServer webSocketServer;
    
    @Autowired
    private SingleWebSocketServer singleWebSocketServer;

    @PostMapping("/single/websocket/{userCode}")
    @ApiOperation("单节点推送")
    public String singleWebsocketMessage(@PathVariable Long userCode, @RequestParam String message) {
        singleWebSocketServer.sendMessage(userCode, message);
        return "OK";
    }
    
    @PostMapping("/sendMessage/{userCode}")
    @ApiOperation("多节点推送")
    public String scoketmessage(@PathVariable("userCode") String userCode, @RequestParam String message) {
        webSocketServer.sendMessage(userCode, message);
        return "ok";
    }
    
    @ApiOperation("当前节点连接的用户")
    @GetMapping("/user")
    public Set<Long> userList() {
        return webSocketServer.userList();
    }
    
    

}
